(function (doc) {
  var oDropdown = doc.getElementsByClassName('dropdown')[0],
    oList = _getChildNode(oDropdown)[1],
    oItems = _getChildNode(oList),
    itemHeight = parseInt(_getStyles(oItems[0], 'height')),
    listHeight = 0,
    timer = null,
    speed = 6;

  function handleMouse(e) {
    var e = e || window.event,
      tar = e.target || e.srcElement,
      type = e.type;

    clearInterval(timer);

    switch (type) {
      case 'mouseenter':
        slideDown();
        break;
      case 'mouseleave':
        slideUp();
        break;
      default:
        break;
    }
  }

  function slideDown() {
    timer = setInterval(function () {
      // >= 200
      if (listHeight >= oItems.length * itemHeight) {
        clearInterval(timer);
      } else {
        listHeight = parseInt(_getStyles(oList, 'height')) + speed;
        oList.style.height = listHeight + 'px';
      }
    }, 1);
  }

  function slideUp() {
    timer = setInterval(function () {
      if (listHeight === oItems.length * itemHeight) {
        clearInterval(timer);
      } else {
        listHeight = parseInt(_getStyles(oList, 'height')) - speed;
        oList.style.height = listHeight + 'px';
      }
    }, 1);
  }

  function _getChildNode(node) {
    var childItem,
      children = node.childNodes,
      len = children.length,
      temp = {
        length: 0,
        push: Array.prototype.push,
        splice: Array.prototype.splice
      };

    for (var i = 0; i < len; i++) {
      childItem = children[i];
      if (childItem.nodeType === 1) {
        temp.push(childItem);
      }
    }
    return temp;
  }

  function _getStyles(elem, prop) {
    if (window.getComputedStyle) {
      if (prop) {
        return window.getComputedStyle(elem, null)[prop];
      } else {
        return window.getComputedStyle(elem, null);
      }
    } else {
      if (prop) {
        return elem.currentStyle[prop];
      } else {
        return elem.currentStyle;
      }
    }
  }

  function bindEvent() {
    oDropdown.addEventListener('mouseenter', handleMouse, false);
    oDropdown.addEventListener('mouseleave', handleMouse, false);
  }

  function init() {
    bindEvent();
  }

  init();
})(document);
